package cn.iocoder.yudao.module.member.agency.controller.app;

import cn.iocoder.yudao.framework.business.eligibility.controller.EligibilityApplyController;
import cn.iocoder.yudao.framework.business.eligibility.pojo.vo.EligibilityApplyCheckVO;
import cn.iocoder.yudao.framework.common.biz.dict.dto.DictDataRespDTO;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.api.infrastructure.dict.DictDataApi;
import cn.iocoder.yudao.module.api.member.agency.vo.AgencyApplyVO;
import cn.iocoder.yudao.module.member.agency.service.AgencyApplyService;
import cn.iocoder.yudao.module.member.agency.vo.AppAgencyApplySaveDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.annotation.security.PermitAll;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
import static cn.iocoder.yudao.module.api.member.DictTypeConstants.MEMBER_AGENCY_LEVEL;

@Tag(name = "用户 App - 招商人员申请")
@RestController
@RequestMapping("/member/agency-apply")
public class AppAgencyApplyController implements EligibilityApplyController<AgencyApplyVO, AppAgencyApplySaveDTO> {

    @Resource
    private AgencyApplyService agencyApplyService;

    @Resource
    private DictDataApi dictDataApi;

    @Operation(summary = "等级列表", description = "用于选择等级，同`/infrastructure/dict-data/type?type=member_agency_level`接口")
    @GetMapping("/levels")
    @PermitAll
    public CommonResult<List<DictDataRespDTO>> getLevels() {
        List<DictDataRespDTO> list = dictDataApi.getDictDataList(MEMBER_AGENCY_LEVEL);
        return success(list);
    }

    @Override
    public CommonResult<EligibilityApplyCheckVO<AgencyApplyVO>> check() {
        EligibilityApplyCheckVO<AgencyApplyVO> respVO = agencyApplyService.check(getLoginUserId(), null);
        return success(respVO);
    }

    @Override
    public CommonResult<Long> apply(AppAgencyApplySaveDTO reqVO) {
        Long id = agencyApplyService.apply(getLoginUserId(), null, reqVO);
        return success(id);
    }

}
